package main

import (
	"fmt"
)

func firstMissingPositive(nums []int) int {
	n := len(nums)
	positions := make([]bool, n+1)
	for _, num := range nums {
		if num <= 0 || num > n {
			continue
		}
		positions[num] = true
	}
	for i := 1; i <= n; i++ {
		if !positions[i] {
			return i
		}
	}
	return n + 1
}

func main() {
	fmt.Println(firstMissingPositive([]int{1, 2, 0}))
	fmt.Println(firstMissingPositive([]int{3, 4, -1, 1}))
	fmt.Println(firstMissingPositive([]int{7, 8, 9, 11, 12}))
}
